package cn.iocoder.yudao.module.biz.controller.admin.licenceSafeMeasuresSetting;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.biz.controller.admin.licenceSafeMeasuresSetting.vo.*;
import cn.iocoder.yudao.module.biz.convert.licenceSafeMeasuresSetting.BizLicenceSafeMeasuresSettingConvert;
import cn.iocoder.yudao.module.biz.dal.dataobject.licenceSafeMeasuresSetting.BizLicenceSafeMeasuresSettingDO;
import cn.iocoder.yudao.module.biz.service.licenceSafeMeasuresSetting.BizLicenceSafeMeasuresSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Api(tags = "管理后台 - 危险作业票安全措施配置")
@RestController
@RequestMapping("/biz/licence-safe-measures-setting")
@Validated
public class BizLicenceSafeMeasuresSettingController {

    @Resource
    private BizLicenceSafeMeasuresSettingService licenceSafeMeasuresSettingService;

    @PostMapping("/create")
    @ApiOperation("创建危险作业票安全措施配置")
//    @PreAuthorize("@ss.hasPermission('biz:licence-safe-measures-setting:create')")
    public CommonResult<String> createLicenceSafeMeasuresSetting(@Valid @RequestBody BizLicenceSafeMeasuresSettingCreateReqVO createReqVO) {
        return success(licenceSafeMeasuresSettingService.createLicenceSafeMeasuresSetting(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新危险作业票安全措施配置")
//    @PreAuthorize("@ss.hasPermission('biz:licence-safe-measures-setting:update')")
    public CommonResult<Boolean> updateLicenceSafeMeasuresSetting(@Valid @RequestBody BizLicenceSafeMeasuresSettingUpdateReqVO updateReqVO) {
        licenceSafeMeasuresSettingService.updateLicenceSafeMeasuresSetting(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除危险作业票安全措施配置")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
//    @PreAuthorize("@ss.hasPermission('biz:licence-safe-measures-setting:delete')")
    public CommonResult<Boolean> deleteLicenceSafeMeasuresSetting(@RequestParam("id") String id) {
        licenceSafeMeasuresSettingService.deleteLicenceSafeMeasuresSetting(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得危险作业票安全措施配置")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
//    @PreAuthorize("@ss.hasPermission('biz:licence-safe-measures-setting:query')")
    public CommonResult<BizLicenceSafeMeasuresSettingRespVO> getLicenceSafeMeasuresSetting(@RequestParam("id") String id) {
        BizLicenceSafeMeasuresSettingDO licenceSafeMeasuresSetting = licenceSafeMeasuresSettingService.getLicenceSafeMeasuresSetting(id);
        return success(BizLicenceSafeMeasuresSettingConvert.INSTANCE.convert(licenceSafeMeasuresSetting));
    }

    @GetMapping("/list")
    @ApiOperation("获得危险作业票安全措施配置列表")
//    @PreAuthorize("@ss.hasPermission('biz:licence-safe-measures-setting:query')")
    public CommonResult<List<BizLicenceSafeMeasuresSettingRespVO>> getLicenceSafeMeasuresSettingList(Integer type) {
        List<BizLicenceSafeMeasuresSettingDO> list = licenceSafeMeasuresSettingService.getLicenceSafeMeasuresSettingByType(type);
        return success(BizLicenceSafeMeasuresSettingConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得危险作业票安全措施配置分页")
//    @PreAuthorize("@ss.hasPermission('biz:licence-safe-measures-setting:query')")
    public CommonResult<PageResult<BizLicenceSafeMeasuresSettingRespVO>> getLicenceSafeMeasuresSettingPage(@Valid BizLicenceSafeMeasuresSettingPageReqVO pageVO) {
        PageResult<BizLicenceSafeMeasuresSettingDO> pageResult = licenceSafeMeasuresSettingService.getLicenceSafeMeasuresSettingPage(pageVO);
        return success(BizLicenceSafeMeasuresSettingConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出危险作业票安全措施配置 Excel")
//    @PreAuthorize("@ss.hasPermission('biz:licence-safe-measures-setting:export')")
//    @OperateLog(type = EXPORT)
    public void exportLicenceSafeMeasuresSettingExcel(@Valid BizLicenceSafeMeasuresSettingExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<BizLicenceSafeMeasuresSettingDO> list = licenceSafeMeasuresSettingService.getLicenceSafeMeasuresSettingList(exportReqVO);
        // 导出 Excel
        List<BizLicenceSafeMeasuresSettingExcelVO> datas = BizLicenceSafeMeasuresSettingConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "危险作业票安全措施配置.xls", "数据", BizLicenceSafeMeasuresSettingExcelVO.class, datas);
    }

}
